import { request } from '@/service/request';

/**
 * 查询大屏设计列表
 */
export function fetchScreenList(params?: Api.Dataplatform.ScreenSearchParams) {
  return request<Api.Dataplatform.ScreenList>({
    url: '/dataplatform/screen/list',
    method: 'get',
    params
  });
}

/**
 * 查询大屏设计详情
 */
export function fetchScreenDetail(id: number) {
  return request<Api.Dataplatform.ScreenDetail>({
    url: `/dataplatform/screen/${id}`,
    method: 'get'
  });
}

/**
 * 新增大屏设计
 */
export function addScreen(data: Api.Dataplatform.ScreenEdit) {
  return request({
    url: '/dataplatform/screen',
    method: 'post',
    data
  });
}

/**
 * 修改大屏设计
 */
export function updateScreen(data: Api.Dataplatform.ScreenEdit) {
  return request({
    url: '/dataplatform/screen',
    method: 'put',
    data
  });
}

/**
 * 删除大屏设计
 */
export function deleteScreen(ids: number[]) {
  return request({
    url: `/dataplatform/screen/${ids.join(',')}`,
    method: 'delete'
  });
}

/**
 * 发布大屏
 */
export function publishScreen(id: number) {
  return request({
    url: `/dataplatform/screen/${id}/publish`,
    method: 'post'
  });
}

/**
 * 下线大屏
 */
export function offlineScreen(id: number) {
  return request({
    url: `/dataplatform/screen/${id}/offline`,
    method: 'post'
  });
}

/**
 * 获取预览URL
 */
export function getPreviewUrl(id: number) {
  return request<string>({
    url: `/dataplatform/screen/${id}/preview-url`,
    method: 'get'
  });
}

/**
 * 查询大屏组件数据
 */
export function queryScreenData(id: number, componentId: string) {
  return request({
    url: `/dataplatform/screen/${id}/data/${componentId}`,
    method: 'get'
  });
}

/**
 * 导出大屏设计
 */
export function exportScreen(params?: Api.Dataplatform.ScreenSearchParams) {
  return request({
    url: '/dataplatform/screen/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  });
}
